
/*
 * @Description: SetTest
 * @Author: 平常心
 * @Date: 2024-09-29 08:40:04
 * @LastEditTime: 2024-09-29 09:47:28
 * @LastEditors: 平常心
 * @FilePath: \java\day25\Test01.java
 * 至若春和景明
 */
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class Test01 {
    public static void main(String[] args) {
        // 实例化一个Set集合
        Set<String> set = new HashSet<>();
        Set<Student> set1 = new HashSet<>();
        // 添加元素
        set.add("hello1");
        set.add("hello2");
        set.add("hello3");
        set.add("hello4");
        set.add("hello5");
        set.add("hello5");
        set.add(null);
        set.add(null);
        set1.add(new Student("张三", 20));
        set1.add(new Student("张三", 20));
        set1.add(new Student("张三", 20));
        set1.add(new Student("张三", 20));

        System.out.println(set.size());
        // 遍历查看元素
        for (Student str : set1) {
            // 无序 不重复
            System.out.println(str);
        }

        // 用迭代器遍历
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            System.out.println("输出: " + it.next());
        }
    }
}